// classLeave.js
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    leaveMsg: {
      placeholderTxt: "请假缘由",
      gtBtnTxt: "确定"
    },
    studentNo: 0,
    studentName: "",
    studentId: 0,
    classSonId:0,
    rowId:0,
    teamId:0,
    why:""
  },

  formSubmit: function(e){
    console.log("to---------",e);
    var that = this;
    var why = e.detail.value.textarea;
    var rowId = parseInt(that.data.rowId);
    var studentId = parseInt(that.data.studentId);
    var classSonId = parseInt(that.data.classSonId);
    var teamId = parseInt(that.data.teamId);
    
    console.log("studentId------",studentId);
    console.log("classSonId------",classSonId);
    console.log("teamId------",teamId);
    console.log("rowId------",rowId);
    console.log("why------",why);
    wx.request({
      url: app.globalData.http + "signIn.do",
      data: {
          why: why,
          rowId: rowId,
          studentId: studentId,
          classSonId: classSonId,
          teamId: teamId,
          status: "1",
          busId: parseInt(wx.getStorageSync("busId")),
          employeesId: parseInt(wx.getStorageSync("employeesId")),
          schoolId: parseInt(wx.getStorageSync("schoolId"))
       },
      header: {
          'content-type': 'application/json'
      },
      success: function(res){
        var code = res.data.code;
        console.log("classLeaveSuccess------",res.data);
        if(code == 100){
          console.log("toSuccess---");
          if(why == "" || why == null){
             wx.showToast({
              title: '不能为空',
              image: "/img/ico/fail.png",
              duration: 2000  
            });
            return;
          }else{
            wx.redirectTo({
              url: "/pages/classSuccess/classSuccess?classSonId="+classSonId+"&rowId="+rowId+"&teamId="+teamId
            })
          }
        } else{
          wx.showToast({
            title: '请假失败',
            image: "/img/ico/fail.png",
            duration: 2000  
          });
          return;
        }
      }
    })
    
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    console.log("学生请假页面加载options--",options);
    that.setData({
      studentName: options.studentName,
      studentNo: options.studentNo,
      studentId : options.studentId,
      classSonId: options.classSonId,
      rowId: options.rowId,
      teamId: options.teamId,
    });
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})